package com.wxc.controller;

import com.wxc.service.UserService;
import com.wxc.vo.Resp;
import com.wxc.vo.req.LoginReqVO;
import com.wxc.vo.resp.LoginRespVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author wxc
 * @date 2021年10月24日 13:15
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户模块相关接口")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    @ApiOperation("登录")
    public Resp<LoginRespVO> login(@RequestBody @Valid LoginReqVO loginReqVO) {
        LoginRespVO loginRespVO = userService.login(loginReqVO);
        return Resp.success(loginRespVO);
    }

    @GetMapping("/test")
    @ApiOperation("测试,需要token")
    public Resp<?> test() {
        return Resp.success(null);
    }

    @GetMapping("/test2")
    @ApiOperation("测试,需要token和sys:user:list权限")
    @RequiresPermissions("sys:user:list")
    // @RequiresRoles("admin")
    public Resp<?> test2() {
        return Resp.success(null);
    }

    @GetMapping("/test3")
    @ApiOperation("测试,需要token和sys:user:add权限")
    @RequiresPermissions("sys:user:add")
    // @RequiresRoles("admin")
    public Resp<?> test3() {
        return Resp.success(null);
    }
}
